<template>
  <div
    id="satelliteresource"
    class="main-div main-div-nopadding"
  >
    <el-container>
      <el-aside
        style="box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);"
        class="background-color-white"
      >
        <div class="aside-header-div">
          <!--卫星资源配置-->
          {{ $t('message.satelliteResource.header') }}
          <div style="float: right">
            <!--添加卫星-->
            <el-button
              v-if="$store.state.is_staff"
              @click="handleSatelliteCreate"
              style="padding: 0"
              type="text"
            >
              <i
                class="el-icon-plus"
                style="font-weight: bold;color: #fff;padding-right: 20px;line-height: 1em;"
              />
            </el-button>
          </div>
        </div>
        <!--卫星资源树-->
        <div
          style="position: relative;"
          class="aside-tree-div"
        >
          <el-button
            v-if="$store.state.is_staff"
            @click="handleDataSynchronize"
            style="position: absolute;top: 0;left: 0;right: 0;width: 100%;height: 45px;z-index: 1"
          >
            同步数据到SAM
          </el-button>
          <el-tree
            :style="$store.state.is_staff ? {'padding-top': '50px'} : {'padding-top': '10px'}"
            style="height: 100%;width: 100%;box-sizing: border-box"
            ref="satelliteTree"
            node-key="node_key"
            @node-click="handleTreeNodeClick"
            :data="aside.tree.data"
            default-expand-all
            highlight-current
            :expand-on-click-node="false"
          >
            <span
              style="flex: 1"
              slot-scope="{ node, data }"
            >
              <!--卫星-->
              <span
                v-if="data.node_type === 'satellite'"
                class="custom-tree-node"
              >
                <span>
                  <img
                    class="tree-node-img"
                    src="@/assets/config/satelliteResource/wx.png"
                  >
                  {{ data.name }}
                </span>
                <span style="padding-right: 10px">
                  <el-button
                    v-if="$store.state.is_staff"
                    @click.stop="handleBeamCreate(data)"
                    class="no-padding"
                    type="text"
                  >
                    <i
                      class="el-icon-plus"
                      style="font-weight: bold"
                    />
                  </el-button>
                  <el-button
                    v-if="$store.state.is_staff"
                    @click.stop="handleSatelliteModify(data)"
                    class="no-padding"
                    type="text"
                  >
                    <img
                      style="width: 12px;"
                      src="@/assets/common/edit.png"
                    >
                  </el-button>
                  <el-button
                    v-if="$store.state.is_staff"
                    @click.stop="handleSatelliteDelete(data)"
                    class="no-padding"
                    type="text"
                  >
                    <i
                      class="el-icon-delete"
                      style="font-weight: bold"
                    />
                  </el-button>
                </span>
              </span>
              <!--波束-->
              <span
                v-if="data.node_type === 'beam'"
                class="custom-tree-node"
              >
                <span>
                  <img
                    class="tree-node-img"
                    src="@/assets/config/satelliteResource/bs.png"
                  >
                  {{ data.name }}
                </span>
                <span style="padding-right: 10px">
                  <el-button
                    v-if="$store.state.is_staff"
                    @click.stop="handleTransponderCreate(data)"
                    class="no-padding"
                    type="text"
                  >
                    <i
                      class="el-icon-plus"
                      style="font-weight: bold"
                    />
                  </el-button>
                  <el-button
                    v-if="$store.state.is_staff"
                    @click.stop="handleBeamModify(data)"
                    class="no-padding"
                    type="text"
                  >
                    <img
                      style="width: 12px;"
                      src="@/assets/common/edit.png"
                    >
                  </el-button>
                  <el-button
                    v-if="$store.state.is_staff"
                    @click.stop="handleBeamDelete(data)"
                    class="no-padding"
                    type="text"
                  >
                    <i
                      class="el-icon-delete"
                      style="font-weight: bold"
                    />
                  </el-button>
                </span>
              </span>
              <!--转发器-->
              <span
                v-if="data.node_type === 'transponder'"
                class="custom-tree-node"
              >
                <span>
                  <img
                    class="tree-node-img"
                    src="@/assets/config/satelliteResource/zfq.png"
                  >
                  {{ data.name }}
                </span>
                <span style="padding-right: 10px">
                  <el-button
                    v-if="$store.state.is_staff"
                    @click.stop="handleTransponderModify(data)"
                    class="no-padding"
                    type="text"
                  >
                    <img
                      style="width: 12px;"
                      src="@/assets/common/edit.png"
                    >
                  </el-button>
                  <el-button
                    v-if="$store.state.is_staff"
                    @click.stop="handleTransponderDelete(data)"
                    class="no-padding"
                    type="text"
                  >
                    <i
                      class="el-icon-delete"
                      style="font-weight: bold"
                    />
                  </el-button>
                </span>
              </span>
            </span>
          </el-tree>
        </div>
      </el-aside>
      <el-main class="el-main-padding el-main-scroll-y">
        <div class="my-breadcrumb-div">
          <i class="el-icon-location my-breadcrumb-icon my-breadcrumb-padding" />
          <el-breadcrumb
            class="my-breadcrumb-padding"
            separator="/"
          > 
            <el-breadcrumb-item>
              <!--配置-->
              {{ $t('message.satelliteResource.breadcrumb.crumb1') }}
            </el-breadcrumb-item>
            <el-breadcrumb-item>
              <!--卫星资源-->
              {{ $t('message.satelliteResource.breadcrumb.crumb2') }}
            </el-breadcrumb-item>
          </el-breadcrumb>
        </div>
        <el-row>
          <el-col>
            <el-card class="margin-bottom-row">
              <div
                style="margin-bottom: 10px"
                class="card-title font-size-el line-height-none"
              >
                <!--当前节点：-->
                {{ $t('message.satelliteResource.card0.header') }}
              </div>
              <div class="card-contain">
                <!--未选择节点时-->
                <div v-if="!aside.tree.currentNode" />
                <!--卫星-->
                <div v-if="aside.tree.currentNode && aside.tree.currentNode.data.node_type === 'satellite'">
                  <el-form
                    inline
                    label-width="100px"
                  >
                    <!--节点名称-->
                    <el-form-item :label="$t('message.satelliteResource.card0.satellite.label1')">
                      {{ aside.tree.currentNode.data.name }}
                    </el-form-item>
                    <!--节点类型-->
                    <el-form-item :label="$t('message.satelliteResource.card0.satellite.label2')">
                      <!--卫星-->
                      {{ $t('message.satelliteResource.card0.satellite.typeName') }}
                    </el-form-item>
                    <!--距离-->
                    <el-form-item :label="$t('message.satelliteResource.card0.satellite.label3')">
                      {{ aside.tree.currentNode.data.distance }}
                    </el-form-item>
                    <!--经度-->
                    <el-form-item :label="$t('message.satelliteResource.card0.satellite.label4')">
                      {{ aside.tree.currentNode.data.longitude }}
                    </el-form-item>
                    <!--纬度-->
                    <el-form-item :label="$t('message.satelliteResource.card0.satellite.label5')">
                      {{ aside.tree.currentNode.data.latitude }}
                    </el-form-item>
                    <!--gt-->
                    <el-form-item :label="$t('message.satelliteResource.card0.satellite.label6')">
                      {{ aside.tree.currentNode.data.gt }}
                    </el-form-item>
                  </el-form>
                  <div>
                    <el-button
                      v-if="$store.state.is_staff"
                      type="primary"
                      size="small"
                      @click="handleBeamCreate(aside.tree.currentNode.data)"
                    >
                      <!--添加波束-->
                      {{ $t('message.satelliteResource.card0.satellite.button1') }}
                    </el-button>
                    <el-button
                      v-if="$store.state.is_staff"
                      type="primary"
                      size="small"
                      @click="handleSatelliteModify(aside.tree.currentNode.data)"
                    >
                      <!--修改-->
                      {{ $t('message.common.button.modify') }}
                    </el-button>
                    <el-button
                      v-if="$store.state.is_staff"
                      type="primary"
                      size="small"
                      @click="handleSatelliteDelete(aside.tree.currentNode.data)"
                    >
                      <!--删除-->
                      {{ $t('message.common.button.delete') }}
                    </el-button>
                  </div>
                </div>
                <!--波束-->
                <div v-if="aside.tree.currentNode && aside.tree.currentNode.data.node_type === 'beam'">
                  <el-form
                    inline
                    label-width="100px"
                  >
                    <!--节点名称-->
                    <el-form-item :label="$t('message.satelliteResource.card0.satellite.label1')">
                      {{ aside.tree.currentNode.data.name }}
                    </el-form-item>
                    <!--节点类型-->
                    <el-form-item label="节点类型：">
                      <!--波束-->
                      {{ $t('message.satelliteResource.card0.beam.typeName') }}
                    </el-form-item>
                  </el-form>
                  <el-button
                    v-if="$store.state.is_staff"
                    type="primary"
                    size="small"
                    @click="handleTransponderCreate(aside.tree.currentNode.data)"
                  >
                    <!--添加转发器-->
                    {{ $t('message.satelliteResource.card0.beam.button1') }}
                  </el-button>
                </div>
                <!--转发器-->
                <div v-if="aside.tree.currentNode && aside.tree.currentNode.data.node_type === 'transponder'">
                  <el-form
                    inline
                    label-width="100px"
                  >
                    <!--节点名称-->
                    <el-form-item :label="$t('message.satelliteResource.card0.transponder.label1')">
                      {{ aside.tree.currentNode.data.name }}
                    </el-form-item>
                    <!--节点类型-->
                    <el-form-item :label="$t('message.satelliteResource.card0.transponder.label2')">
                      <!--转发器-->
                      {{ $t('message.satelliteResource.card0.transponder.typeName') }}
                    </el-form-item>
                    <!--频差-->
                    <el-form-item :label="$t('message.satelliteResource.card0.transponder.label3')">
                      {{ $service.miliFormat(aside.tree.currentNode.data.frequency_difference / 1000) }} KHz
                    </el-form-item>
                    <!--增益-->
                    <el-form-item :label="$t('message.satelliteResource.card0.transponder.label4')">
                      {{ aside.tree.currentNode.data.gain }}
                    </el-form-item>
                  </el-form>
                  <div>
                    <el-button
                      v-if="$store.state.is_staff"
                      type="primary"
                      size="small"
                      @click="handleFreqSegmentCreate"
                    >
                      <!--添加可用频率-->
                      {{ $t('message.satelliteResource.card0.transponder.button1') }}
                    </el-button>
                    <el-button
                      v-if="$store.state.is_staff"
                      type="primary"
                      size="small"
                      @click="handleTransponderModify(aside.tree.currentNode.data)"
                    >
                      <!--修改-->
                      {{ $t('message.common.button.modify') }}
                    </el-button>
                    <el-button
                      v-if="$store.state.is_staff"
                      type="primary"
                      size="small"
                      @click="handleTransponderDelete(aside.tree.currentNode.data)"
                    >
                      <!--删除-->
                      {{ $t('message.common.button.delete') }}
                    </el-button>
                  </div>
                </div>
              </div>
            </el-card>
          </el-col>
        </el-row>
        <!--可用频率-->
        <el-row>
          <el-col>
            <el-card class="margin-bottom-row">
              <div
                style="margin-bottom: 10px"
                class="card-title font-size-el line-height-none"
              >
                <!--可用频率：-->
                {{ $t('message.satelliteResource.card1.title') }}
              </div>
              <el-table
                v-loading="freqSegment.table.loading"
                ref="freqSegmentTable"
                header-cell-class-name="my-table-header-cell"
                cell-class-name="my-table-cell my-table-cell-pointer"
                @row-click="handleFreqSegmentTableRowClick"
                @expand-change="handleFreqSegmentTableRowExpandChange"
                height="400px"
                highlight-current-row
                :data="freqSegmentTable"
              >
                <el-table-column type="expand">
                  <template slot-scope="props">
                    <el-form
                      label-position="right"
                      label-width="120px"
                      class="demo-table-expand"
                    >
                      <el-form-item :label="$t('message.satelliteResource.card1.table.expand.label')">
                        <el-button
                          v-if="$store.state.is_staff"
                          @click="handleTimePeriodCreate(props.row.id)"
                          type="text"
                          size="mini"
                        >
                          <font-awesome-icon
                            icon="plus"
                            size="lg"
                          />
                        </el-button>
                      </el-form-item>
                      <el-form-item>
                        {{ props.row.service_time.length === 0 ? $t('message.satelliteResource.card1.table.expand.wholeDay') : '' }}
                      </el-form-item>
                      <el-form-item
                        v-for="(value, index) in props.row.service_time"
                        :key="value.id"
                      >
                        <span slot="label">
                          #{{ index + 1 }}
                        </span>
                        <span>{{ $t('message.satelliteResource.card1.table.expand.startTime') }}: {{ value.start_time }}</span>
                        <span style="margin-left: 20px">{{ $t('message.satelliteResource.card1.table.expand.endTime') }}: {{ value.end_time }}</span>
                        <el-button
                          v-if="$store.state.is_staff"
                          style="margin-left: 15px"
                          @click.stop="handleTimePeriodModify(value)"
                          type="text"
                        >
                          <img
                            width="12px"
                            src="@/assets/common/edit.png"
                          >
                        </el-button>
                        <el-button
                          v-if="$store.state.is_staff"
                          style="padding: 0"
                          @click.stop="handleTimePeriodDelete(value)"
                          type="text"
                        >
                          <img
                            width="12px"
                            src="@/assets/common/delete.png"
                          >
                        </el-button>
                      </el-form-item>
                    </el-form>
                  </template>
                </el-table-column>
                <!--上行波束-->
                <el-table-column
                  :label="$t('message.satelliteResource.card1.table.col1')"
                  prop="up_beam_name"
                />
                <!--下行波束-->
                <el-table-column
                  :label="$t('message.satelliteResource.card1.table.col2')"
                  prop="down_beam_name"
                />
                <!--转发器-->
                <el-table-column
                  :label="$t('message.satelliteResource.card1.table.col3')"
                  prop="transponder_name"
                />
                <!--&lt;!&ndash;上行起始频点&ndash;&gt;-->
                <!--<el-table-column-->
                <!--  :label="$t('message.satelliteResource.card1.table.col3')"-->
                <!--  prop="up_freq_begin"-->
                <!--/>-->
                <!--&lt;!&ndash;上行终止频点&ndash;&gt;-->
                <!--<el-table-column-->
                <!--  :label="$t('message.satelliteResource.card1.table.col4')"-->
                <!--  prop="up_freq_end"-->
                <!--/>-->
                <!--下行起始频点-->
                <el-table-column
                  :label="$t('message.satelliteResource.card1.table.col5')"
                  prop="down_freq_begin_format"
                />
                <!--下行终止频点-->
                <el-table-column
                  :label="$t('message.satelliteResource.card1.table.col6')"
                  prop="down_freq_end_format"
                />
                <!--是否可用-->
                <el-table-column :label="$t('message.satelliteResource.card1.table.col8')">
                  <template slot-scope="scope">
                    <!--<el-tag-->
                    <!--  style="color: #fff"-->
                    <!--  disable-transitions-->
                    <!--  size="small"-->
                    <!--  :style="scope.row.enable ? 'background-color: #5e88c2' : 'background-color: #c4c4c4'"-->
                    <!--&gt;-->
                    <!--  {{ $t('message.satelliteResource.card1.table.col8tag', { enable: scope.row.enable }) }}-->
                    <!--</el-tag>-->
                    <span>
                      <font-awesome-icon
                        icon="circle"
                        :color="scope.row.enable ? '#5e88c2' : '#c4c4c4'"
                      />
                      {{ $t('message.satelliteResource.card1.table.col8tag', { enable: scope.row.enable }) }}
                    </span>
                  </template>
                </el-table-column>
                <!--操作-->
                <el-table-column
                  v-if="$store.state.is_staff"
                  :label="$t('message.common.label.operate')"
                >
                  <template slot-scope="scope">
                    <!--添加控制信道-->
                    <el-button
                      style="padding: 0;vertical-align: text-bottom"
                      @click.stop="handleControlChannelCreate(scope.row)"
                      type="text"
                    >
                      <font-awesome-icon
                        icon="plus"
                        size="lg"
                      />
                    </el-button>
                    <!--修改频率段-->
                    <el-button
                      style="padding: 0"
                      @click.stop="handleFreqSegmentModify(scope.row)"
                      type="text"
                    >
                      <img src="@/assets/common/edit.png">
                    </el-button>
                    <!--删除频率段-->
                    <el-button
                      style="padding: 0 0 0 5px"
                      @click.stop="handleFreqSegmentDelete(scope.row)"
                      type="text"
                    >
                      <img src="@/assets/common/delete.png">
                    </el-button>
                    <!--频率段的开关-->
                    <el-button
                      class="button-switch"
                      @click="handleFreqSegmentEnable(scope.$index,scope.row)"
                      type="text"
                    >
                      <img
                        v-if="scope.row.enable"
                        src="@/assets/common/switch/on.png"
                      >
                      <img
                        v-else
                        src="@/assets/common/switch/off.png"
                      >
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
            </el-card>
          </el-col>
        </el-row>
        <!--控制信道-->
        <el-row>
          <el-col>
            <el-card class="margin-bottom-row">
              <div
                style="margin-bottom: 10px"
                class="card-title font-size-el line-height-none"
              >
                <!--控制信道：-->
                {{ $t('message.satelliteResource.card2.title') }}
              </div>
              <el-table
                v-loading="controlChannel.table.loading"
                height="300px"
                header-cell-class-name="my-table-header-cell"
                cell-class-name="my-table-cell"
                :data="controlChannelTable"
              >
                <!--发送频点-->
                <!--<el-table-column-->
                <!--  :label="$t('message.satelliteResource.card2.table.col1')"-->
                <!--  prop="up_freq_point"-->
                <!--/>-->
                <!--接收频点-->
                <el-table-column
                  :label="$t('message.satelliteResource.card2.table.col2')"
                  prop="down_freq_point_format"
                />
                <!--带宽-->
                <el-table-column
                  :label="$t('message.satelliteResource.card2.table.col3')"
                  prop="band_width_format"
                />
                <!--功率-->
                <el-table-column
                  :label="$t('message.satelliteResource.card2.table.col4')"
                  prop="power"
                />
                <!--控制信道类型-->
                <el-table-column
                  :label="$t('message.satelliteResource.card2.table.col5')"
                  prop="kind"
                >
                  <template slot-scope="scope">
                    <span>{{ $t(`message.define.controlChannel.kind.${scope.row.kind}`) }}</span>
                  </template>
                </el-table-column>
                <!--操作-->
                <el-table-column
                  v-if="$store.state.is_staff"
                  :label="$t('message.common.label.operate')"
                >
                  <template slot-scope="scope">
                    <el-button
                      style="padding: 0"
                      @click="handleControlChannelModify(scope.row)"
                      type="text"
                    >
                      <img src="@/assets/common/edit.png">
                    </el-button>
                    <el-button
                      style="padding: 0 0 0 5px"
                      @click="handleControlChannelDelete(scope.row)"
                      type="text"
                    >
                      <img src="@/assets/common/delete.png">
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
            </el-card>
          </el-col>
        </el-row>
      </el-main>
    </el-container>

    <!--dialog-->
    <!--卫星-->
    <el-dialog
      :title="$t('message.satelliteResource.dialog.satellite.title', {operate: satellite.method || 'post'})"
      width="20%"
      @closed="handleSatelliteDialogClosed"
      :visible.sync="satellite.visible"
    >
      <el-form
        ref="satelliteForm"
        :model="satellite.form"
        :rules="$store.state.satellite.checkRules"
        label-width="100px"
      >
        <el-form-item
          :label="$t('message.satelliteResource.dialog.satellite.form.label1')"
          prop="name"
        >
          <el-input
            :maxlength="$store.state.parameters.inputLengthLimit.text"
            show-word-limit
            v-model="satellite.form.name"
          />
        </el-form-item>
        <el-form-item
          :label="$t('message.satelliteResource.dialog.satellite.form.label2')"
          prop="distance"
        >
          <el-input v-model="satellite.form.distance">
            <template slot="append">
              KM
            </template>
          </el-input>
        </el-form-item>
        <el-form-item
          :label="$t('message.satelliteResource.dialog.satellite.form.label3')"
          prop="longitude"
        >
          <el-input
            @blur="satellite.form.longitude = $service.valueControl.longitudeLimit(satellite.form.longitude)"
            v-model="satellite.form.longitude"
          />
        </el-form-item>
        <el-form-item
          :label="$t('message.satelliteResource.dialog.satellite.form.label4')"
          prop="latitude"
        >
          <el-input
            @blur="satellite.form.latitude = $service.valueControl.latitudeLimit(satellite.form.latitude)"
            v-model="satellite.form.latitude"
          />
        </el-form-item>
        <el-form-item
          :label="$t('message.satelliteResource.dialog.satellite.form.label5')"
          prop="gt"
        >
          <el-input
            @blur="satellite.form.gt = $service.valueControl.satelliteGtLimit(satellite.form.gt)"
            v-model="satellite.form.gt"
          />
        </el-form-item>
        <el-form-item class="button-form-item">
          <el-button
            :loading="satellite.buttonLoading"
            @click="submitForm('satelliteForm')"
            type="primary"
          >
            {{ $t('message.common.button.confirm') }}
          </el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <!--波束-->
    <el-dialog
      :title="$t('message.satelliteResource.dialog.beam.title', {operate: beam.method || 'post'})"
      width="20%"
      @closed="handleBeamDialogClosed"
      :visible.sync="beam.visible"
    >
      <el-form
        class="demo-ruleform"
        ref="beamForm"
        :model="beam.form"
        :rules="$store.state.beam.checkRules"
        label-width="100px"
      >
        <el-form-item
          :label="$t('message.satelliteResource.dialog.beam.form.label1')"
          prop="name"
        >
          <el-input
            :maxlength="$store.state.parameters.inputLengthLimit.text"
            show-word-limit
            v-model="beam.form.name"
          />
        </el-form-item>
        <el-form-item class="button-form-item">
          <el-button
            :loading="beam.buttonLoading"
            @click="submitForm('beamForm')"
            type="primary"
          >
            {{ $t('message.common.button.confirm') }}
          </el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <!--转发器-->
    <el-dialog
      :title="$t('message.satelliteResource.dialog.transponder.title', {operate: transponder.method || 'post'})"
      width="20%"
      @closed="handleTransponderDialogClosed"
      :visible.sync="transponder.visible"
    >
      <el-form
        class="demo-ruleform"
        ref="transponderForm"
        :model="transponder.form"
        :rules="$store.state.transponder.checkRules"
        label-width="100px"
      >
        <!--转发器名称-->
        <el-form-item
          :label="$t('message.satelliteResource.dialog.transponder.form.label1')"
          prop="name"
        >
          <el-input
            :maxlength="$store.state.parameters.inputLengthLimit.text"
            show-word-limit
            v-model="transponder.form.name"
          />
        </el-form-item>
        <!--转发器增益-->
        <el-form-item
          :label="$t('message.satelliteResource.dialog.transponder.form.label2')"
          prop="gain"
        >
          <el-input
            @blur="transponder.form.gain = $service.valueControl.transponderGainLimit(transponder.form.gain)"
            v-model="transponder.form.gain"
          />
        </el-form-item>
        <!--转发器频差-->
        <el-form-item
          :label="$t('message.satelliteResource.dialog.transponder.form.label3')"
          prop="frequency_difference"
        >
          <!--输入提示-->
          <el-popover
            v-if="transponder.method === 'post'"
            placement="right"
            :title="$t('message.common.label.inputPrompt')"
            width="200"
            trigger="focus"
          >
            <span>{{ $service.miliFormat(transponder.form.frequency_difference) }} KHz</span>
            <el-input
              slot="reference"
              :maxlength="$store.state.parameters.inputLengthLimit.freq"
              show-word-limit
              v-model.number="transponder.form.frequency_difference"
            >
              <template slot="append">
                KHz
              </template>
            </el-input>
          </el-popover>
          <span v-else-if="transponder.method === 'patch'">{{ transponder.form.frequency_difference }} KHz</span>
        </el-form-item>
        <el-form-item class="button-form-item">
          <el-button
            :loading="transponder.buttonLoading"
            @click="submitForm('transponderForm')"
            type="primary"
          >
            {{ $t('message.common.button.confirm') }}
          </el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <!--可用频率-->
    <el-dialog
      v-loading="freqSegment.loading"
      :title="$t('message.satelliteResource.dialog.freqSegment.title', {operate: freqSegment.method || 'post'})"
      width="20%"
      @open="handleFreqSegmentDialogOpen"
      @closed="handleFreqSegmentDialogClosed"
      :visible.sync="freqSegment.visible"
    >
      <el-form
        class="demo-ruleform"
        ref="freqSegmentForm"
        :model="freqSegment.form"
        :rules="$store.state.freqSegment.checkRules"
        label-width="120px"
      >
        <!--所属转发器-->
        <el-form-item :label="$t('message.satelliteResource.dialog.freqSegment.form.label1')">
          {{ aside.tree.currentNode ? aside.tree.currentNode.data.name : '' }}
        </el-form-item>
        <!--上行波束-->
        <el-form-item
          :label="$t('message.satelliteResource.dialog.freqSegment.form.label2')"
          prop="up_beam"
        >
          <el-select v-model="freqSegment.form.up_beam">
            <el-option
              v-for="item in freqSegment.up_beamOption"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
        <!--下行起始频点-->
        <el-form-item
          :label="$t('message.satelliteResource.dialog.freqSegment.form.label5')"
          prop="down_freq_begin"
        >
          <!--输入提示-->
          <el-popover
            placement="right"
            :title="$t('message.common.label.inputPrompt')"
            width="200"
            trigger="focus"
          >
            <span>{{ $service.miliFormat(freqSegment.form.down_freq_begin) }} KHz</span>
            <el-input
              slot="reference"
              :maxlength="$store.state.parameters.inputLengthLimit.freq"
              show-word-limit
              v-model.number="freqSegment.form.down_freq_begin"
            >
              <template slot="append">
                KHz
              </template>
            </el-input>
          </el-popover>
        </el-form-item>
        <!--下行终止频点-->
        <el-form-item
          :label="$t('message.satelliteResource.dialog.freqSegment.form.label6')"
          prop="down_freq_end"
        >
          <!--输入提示-->
          <el-popover
            placement="right"
            :title="$t('message.common.label.inputPrompt')"
            width="200"
            trigger="focus"
          >
            <span>{{ $service.miliFormat(freqSegment.form.down_freq_end) }} KHz</span>
            <el-input
              slot="reference"
              :maxlength="$store.state.parameters.inputLengthLimit.freq"
              show-word-limit
              v-model.number="freqSegment.form.down_freq_end"
            >
              <template slot="append">
                KHz
              </template>
            </el-input>
          </el-popover>
        </el-form-item>
        <el-form-item class="button-form-item">
          <el-button
            :loading="freqSegment.buttonLoading"
            @click="submitForm('freqSegmentForm')"
            type="primary"
          >
            {{ $t('message.common.button.confirm') }}
          </el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <!--频率段时间段-->
    <el-dialog
      :title="$t('message.satelliteResource.dialog.freqSegmentTimePeriod.title', {operate: timePeriod.method})"
      width="20%"
      :visible.sync="timePeriod.visible"
    >
      <el-form
        class="demo-ruleform"
        ref="timePeriodForm"
        :model="timePeriod.form"
        :rules="$store.state.freqSegment.timePeriodCheckRules"
        label-width="100px"
      >
        <!--开始时间-->
        <el-form-item
          :label="$t('message.satelliteResource.dialog.freqSegmentTimePeriod.form.label1')"
          prop="start_time"
        >
          <el-time-picker
            :default-value="getTimePeriodDefault()"
            arrow-control
            v-model="timePeriod.form.start_time"
            :picker-options="{
              format: 'HH:mm'
            }"
            :placeholder="$t('message.common.placeholder.select.startTime')"
          />
        </el-form-item>
        <!--结束时间-->
        <el-form-item
          :label="$t('message.satelliteResource.dialog.freqSegmentTimePeriod.form.label2')"
          prop="end_time"
        >
          <el-time-picker
            :default-value="getTimePeriodDefault()"
            arrow-control
            v-model="timePeriod.form.end_time"
            :picker-options="{
              format: 'HH:mm',
              minTime: timePeriod.form.start_time
            }"
            :placeholder="$t('message.common.placeholder.select.endTime')"
          />
        </el-form-item>
        <el-form-item class="button-form-item">
          <el-button
            :loading="timePeriod.submitButtonLoading"
            @click="submitForm('timePeriodForm')"
            type="primary"
          >
            {{ $t('message.common.button.confirm') }}
          </el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <!--控制信道-->
    <el-dialog
      v-loading="controlChannel.loading"
      :title="$t('message.satelliteResource.dialog.controlChannel.title', {operate: controlChannel.method || 'post'})"
      width="20%"
      @open="handleControlChannelDialogOpen"
      @closed="handleControlChannelDialogClosed"
      :visible.sync="controlChannel.visible"
    >
      <el-form
        class="demo-ruleform"
        ref="controlChannelForm"
        :model="controlChannel.form"
        :rules="$store.state.controlChannel.checkRules"
        label-width="120px"
      >
        <!--类型-->
        <el-form-item
          :label="$t('message.satelliteResource.dialog.controlChannel.form.label1')"
          prop="kind"
        >
          <el-select
            :disabled="controlChannel.method !== 'post'"
            v-model="controlChannel.form.kind"
          >
            <el-option
              v-for="item in controlChannel.kindOption"
              :key="item.kind"
              :label="item.name"
              :value="item.kind"
            />
          </el-select>
        </el-form-item>
        <!--功率-->
        <el-form-item
          :label="$t('message.satelliteResource.dialog.controlChannel.form.label2')"
          prop="power"
        >
          <el-input
            v-model="controlChannel.form.power"
          >
            <template slot="append">
              dBw
            </template>
          </el-input>
        </el-form-item>
        <!--接收频点-->
        <el-form-item
          :label="$t('message.satelliteResource.dialog.controlChannel.form.label4')"
          prop="down_freq_point"
        >
          <!--输入提示-->
          <el-popover
            placement="right"
            :title="$t('message.common.label.inputPrompt')"
            width="200"
            trigger="focus"
          >
            <span>{{ $service.miliFormat(controlChannel.form.down_freq_point) }} KHz</span>
            <el-input
              slot="reference"
              :maxlength="$store.state.parameters.inputLengthLimit.freq"
              show-word-limit
              v-model.number="controlChannel.form.down_freq_point"
            >
              <template slot="append">
                KHz
              </template>
            </el-input>
          </el-popover>
        </el-form-item>
        <!--提交-->
        <el-form-item class="button-form-item">
          <el-button
            :loading="controlChannel.buttonLoading"
            @click="submitForm('controlChannelForm')"
            type="primary"
          >
            {{ $t('message.common.button.confirm') }}
          </el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import common from '@/common'
export default {
  name: 'Resource',
  computed: {
    freqSegmentTable: {
      get () {
        return this.$store.getters.getFreqSegmentTableData
      },
      set (val) {
        this.$store.commit(`setFreqSegmentTable`, val)
      }
    },
    controlChannelTable: {
      get () {
        return this.$store.getters.getControlChannelTableData
      },
      set (val) {
        this.$store.commit(`setControlChannelTable`, val)
      }
    }
  },
  data () {
    return {
      aside: {
        loading: false,
        tree: {
          data: [],
          currentNode: null
        }
      },

      satellite: {
        visible: false,
        buttonLoading: false,

        method: '',
        id: '',
        form: {
          name: '',
          distance: '',
          longitude: '',
          latitude: '',
          gt: ''
        }
      },

      beam: {
        visible: false,
        buttonLoading: false,

        method: '',
        id: '',
        satellite: '',
        form: {
          name: ''
        }
      },

      transponder: {
        visible: false,
        buttonLoading: false,

        method: '',
        id: '',
        down_beam: '',
        form: {
          name: '',
          gain: '',
          frequency_difference: ''
        }
      },

      freqSegment: {
        visible: false,
        loading: false,
        buttonLoading: false,

        method: '',
        id: '',
        transponder: '',
        up_beamOption: [],
        form: {
          up_beam: '',
          down_freq_begin: '',
          down_freq_end: ''
        },

        table: {
          loading: false,
          expand: [],
          currentRow: null,
          data: []
        }
      },

      timePeriod: {
        visible: false,
        buttonLoading: false,

        method: '',
        id: '',
        freq_segment: '',
        form: {
          start_time: '',
          end_time: ''
        }
      },

      controlChannel: {
        visible: false,
        loading: false,
        buttonLoading: false,
        popover: {
          down_freq_point_visible: false
        },

        method: '',
        id: '',
        freqSegment: '',
        kindOption: [],
        form: {
          kind: '',
          power: '',
          down_freq_point: ''
        },

        table: {
          loading: false,
          data: []
        }
      }
    }
  },
  // 在离开当前页面前，清空频率表格中的数据
  beforeRouteLeave (to, from, next) {
    let self = this
    self.freqSegmentTable = []
    self.controlChannelTable = []
    next()
  },
  mounted () {
    let self = this
    self.$nextTick(() => {
      self.getSatelliteTree()
    })
  },
  methods: {
    async getSatelliteTree () {
      let self = this
      try {
        self.aside.loading = true
        let response = await self.$store.dispatch(`axios`, {
          method: 'get',
          url: '/api/abs/resources/satellite_tree/'
        })
        self.aside.tree.data = response.data
      } finally {
        self.aside.loading = false
      }
    },
    async getFreqSegmentTableData () {
      let self = this
      if (self.aside.tree.currentNode === null) {
        // 未选择卫星资源树节点
        self.$message.error(self.$t('message.satelliteResource.errors.err3'))
        return
      }
      let freqSegmentExpandId = self.freqSegment.table.expand
      self.controlChannelTable = []
      try {
        self.freqSegment.table.loading = true
        await self.$store.dispatch(`getFreqSegmentTableData`, {
          node_type: self.aside.tree.currentNode.data.node_type,
          id: self.aside.tree.currentNode.data.id
        })
        self.$store.commit('clearControlChannelTable')
        // 设置展开的行
        for (let item of self.freqSegmentTable) {
          if (freqSegmentExpandId.find(expandid => expandid === item.id)) {
            self.$refs.freqSegmentTable.toggleRowExpansion(item, true)
          }
        }
      } finally {
        self.freqSegment.table.loading = false
      }
    },
    // 数据同步服务
    async handleSatelliteTreeUpdate () {
      let self = this
      if (self.aside.tree.currentNode) {
        let currentNode = self.$refs.satelliteTree.getNode(self.aside.tree.currentNode.data.node_key)
        if (currentNode) {
          self.aside.tree.currentNode = currentNode
          // console.log(currentNode)
          self.$refs.satelliteTree.setCurrentKey(currentNode.data.node_key)
        } else {
          self.aside.tree.currentNode = null
          self.freqSegmentTable = []
          self.controlChannelTable = []
        }
      }
    },
    handleTreeNodeClick (data, node) {
      let self = this
      self.aside.tree.currentNode = node
      self.getFreqSegmentTableData()
    },
    handleFreqSegmentTableRowClick (row) {
      let self = this
      self.freqSegment.table.currentRow = row
      self.getControlChannelsTableData()
    },
    handleFreqSegmentTableRowExpandChange (row, expandedRows) {
      let self = this
      self.freqSegment.table.expand = expandedRows.map(item => {
        return item.id
      })
    },
    async getControlChannelsTableData () {
      let self = this
      try {
        self.controlChannel.table.loading = true
        await self.$store.dispatch(`getControlChannelTableData`, self.freqSegment.table.currentRow.id)
      } finally {
        self.controlChannel.table.loading = false
      }
    },
    // 卫星
    handleSatelliteCreate () {
      let self = this
      self.satellite.method = 'post'
      self.satellite.form.distance = 36000
      self.satellite.visible = true
    },
    handleSatelliteModify (data) {
      let self = this
      self.satellite.method = 'patch'
      self.satellite.id = data.id
      self.satellite.form.name = data.name
      self.satellite.form.distance = data.distance
      self.satellite.form.longitude = data.longitude
      self.satellite.form.latitude = data.latitude
      self.satellite.form.gt = data.gt
      self.satellite.visible = true
    },
    async handleSatelliteDelete (data) {
      let self = this
      try {
        await self.$confirm(self.$t('message.satelliteResource.dialog.satellite.deleteConfirm', { name: data.name }), self.$t('message.common.label.prompt'), {
          confirmButtonText: self.$t('message.common.button.confirm'),
          cancelButtonText: self.$t('message.common.button.cancel'),
          type: 'warning'
        })
      } catch (e) {
        return
      }
      await self.$store.dispatch(`axios`, {
        method: 'delete',
        url: `/api/abs/resources/satellites/${data.id}/`
      })
      self.$refs.satelliteTree.remove(data.node_key)
      self.handleSatelliteTreeUpdate()
      self.$message({
        message: self.$t('message.common.info.deleteSuccess'),
        type: 'success'
      })
    },
    handleSatelliteDialogClosed () {
      let self = this
      self.satellite.method = ''
      self.satellite.id = ''
      self.satellite.form.name = ''
      self.satellite.form.distance = ''
      self.satellite.form.longitude = ''
      self.satellite.form.latitude = ''
      self.satellite.form.gt = ''
      self.$refs.satelliteForm.resetFields()
    },
    // 波束
    handleBeamCreate (data) {
      let self = this
      self.beam.satellite = data.id
      self.beam.method = 'post'
      self.beam.visible = true
    },
    handleBeamModify (data) {
      let self = this
      self.beam.id = data.id
      self.beam.form.name = data.name
      self.beam.method = 'patch'
      self.beam.visible = true
    },
    async handleBeamDelete (data) {
      let self = this
      try {
        await self.$confirm(self.$t('message.satelliteResource.dialog.beam.deleteConfirm', { name: data.name }), self.$t('message.common.label.prompt'), {
          confirmButtonText: self.$t('message.common.button.confirm'),
          cancelButtonText: self.$t('message.common.button.cancel'),
          type: 'warning'
        })
      } catch (e) {
        return
      }
      await self.$store.dispatch(`axios`, {
        method: 'delete',
        url: `/api/abs/resources/beams/${data.id}/`
      })
      self.$refs.satelliteTree.remove(data.node_key)
      self.handleSatelliteTreeUpdate()
      self.$message({
        message: self.$t('message.common.info.deleteSuccess'),
        type: 'success'
      })
    },
    handleBeamDialogClosed () {
      let self = this
      self.beam.method = ''
      self.beam.id = ''
      self.beam.form.name = ''
      self.$refs.beamForm.resetFields()
    },
    // 转发器
    handleTransponderCreate (data) {
      let self = this
      self.transponder.method = 'post'
      self.transponder.down_beam = data.id
      self.transponder.visible = true
    },
    handleTransponderModify (data) {
      let self = this
      self.transponder.method = 'patch'
      self.transponder.id = data.id
      self.transponder.form.name = data.name
      self.transponder.form.gain = data.gain
      self.transponder.form.frequency_difference = data.frequency_difference / 1000
      self.transponder.visible = true
    },
    async handleTransponderDelete (data) {
      let self = this
      try {
        await self.$confirm(self.$t('message.satelliteResource.dialog.transponder.deleteConfirm', { name: data.name }), self.$t('message.common.label.prompt'), {
          confirmButtonText: self.$t('message.common.button.confirm'),
          cancelButtonText: self.$t('message.common.button.cancel'),
          type: 'warning'
        })
      } catch (e) {
        return
      }
      await self.$store.dispatch(`axios`, {
        method: 'delete',
        url: `/api/abs/resources/transponders/${data.id}/`
      })
      self.$refs.satelliteTree.remove(data.node_key)
      self.handleSatelliteTreeUpdate()
      self.$message({
        message: self.$t('message.common.info.deleteSuccess'),
        type: 'success'
      })
    },
    handleTransponderDialogClosed () {
      let self = this
      self.transponder.method = ''
      self.transponder.id = ''
      self.transponder.form.name = ''
      self.transponder.form.gain = ''
      self.transponder.form.frequency_difference = ''
    },
    // 频率段
    async handleFreqSegmentEnable (index, row) {
      let self = this
      try {
        self.freqSegmentTableDataLoading = true
        await self.$store.dispatch(`axios`, {
          method: 'post',
          url: `/api/abs/resources/freq_segments/${row.id}/${row.enable ? 'disable' : 'enable'}/`
        })
        self.$message.success(self.$t('message.satelliteResource.dialog.freqSegment.enableResult', { enable: row.enable }))
      } finally {
        self.getFreqSegmentTableData()
      }
    },
    async handleFreqSegmentCreate () {
      let self = this
      // if (self.breadcrumbArr.length === 0 || self.breadcrumbArr[self.breadcrumbArr.length - 1].node_type !== 'transponder') {
      //   self.$message({
      //     message: self.$t('message.satelliteResource.errors.err1'),
      //     type: 'error'
      //   })
      //   return
      // }
      self.freqSegment.method = 'post'
      self.freqSegment.transponder = self.aside.tree.currentNode.data.id
      self.freqSegment.visible = true
    },
    async handleFreqSegmentModify (row) {
      let self = this
      self.freqSegment.method = 'patch'
      self.freqSegment.id = row.id
      self.freqSegment.form.up_beam = row.up_beam
      self.freqSegment.form.down_freq_begin = row.down_freq_begin
      self.freqSegment.form.down_freq_end = row.down_freq_end
      self.freqSegment.visible = true
    },
    async handleFreqSegmentDelete (row) {
      let self = this
      try {
        await self.$confirm(self.$t('message.satelliteResource.dialog.freqSegment.deleteConfirm'), self.$t('message.common.label.prompt'), {
          confirmButtonText: self.$t('message.common.button.confirm'),
          cancelButtonText: self.$t('message.common.button.cancel'),
          type: 'warning'
        })
      } catch (e) {
        return
      }
      try {
        await self.$store.dispatch(`axios`, {
          method: 'delete',
          url: `/api/abs/resources/freq_segments/${row.id}/`
        })
        self.$message({
          message: self.$t('message.common.info.deleteSuccess'),
          type: 'success'
        })
        if (!self.checkedFreqSegment) {
          if (self.checkedFreqSegment.id === row.id) {
            self.checkedFreqSegment = null
          }
        }
      } finally {
        self.getFreqSegmentTableData()
      }
    },
    async handleFreqSegmentDialogOpen () {
      let self = this
      try {
        self.freqSegment.loading = true
        let satelliteId = self.aside.tree.currentNode.parent.parent.data.id
        await self.$store.dispatch(`getBeamOption`, satelliteId)
        self.freqSegment.up_beamOption = [...self.$store.state.beam.beamOption]
      } finally {
        self.freqSegment.loading = false
      }
    },
    handleFreqSegmentDialogClosed () {
      let self = this
      self.freqSegment.method = ''
    },
    // 时间段
    getTimePeriodDefault () {
      let date = new Date()
      date.setMinutes(0)
      date.setSeconds(0)
      return date.toString()
    },
    handleTimePeriodCreate (freqSegmentId) {
      let self = this
      self.timePeriod.model = 'post'
      self.timePeriod.freq_segment = freqSegmentId
      self.timePeriod.form.start_time = ''
      self.timePeriod.form.end_time = ''
      self.timePeriod.visible = true
    },
    handleTimePeriodModify (value) {
      let self = this
      self.timePeriod.model = 'patch'
      self.timePeriod.id = value.id
      self.timePeriod.form.start_time = new Date(2019, 1, 1, value.start_time.split(':')[0], value.start_time.split(':')[1], value.start_time.split(':')[2])
      self.timePeriod.form.end_time = new Date(2019, 1, 1, value.end_time.split(':')[0], value.end_time.split(':')[1], value.end_time.split(':')[2])
      self.timePeriod.visible = true
    },
    async handleTimePeriodDelete (timeItem) {
      let self = this
      try {
        await self.$confirm(self.$t('message.satelliteResource.dialog.freqSegmentTimePeriod.deleteConfirm', {
          start_time: timeItem.start_time,
          end_time: timeItem.end_time
        }), self.$t('message.common.label.prompt'), {
          confirmButtonText: self.$t('message.common.button.confirm'),
          cancelButtonText: self.$t('message.common.button.cancel'),
          type: 'warning'
        })
      } catch (e) {
        return
      }
      await self.$store.dispatch(`axios`, {
        method: 'delete',
        url: `/api/abs/resources/freq_segment_service_time/${timeItem.id}/`
      })
      self.$message({
        message: self.$t('message.common.info.deleteSuccess'),
        type: 'success'
      })
      self.getFreqSegmentTableData()
    },
    // 控制信道
    async handleControlChannelCreate (row) {
      let self = this
      self.controlChannel.method = 'post'
      self.controlChannel.freqSegment = row.id
      // 添加操作时，重新设置currentRow的值，来获取更新后的数据
      self.freqSegment.table.currentRow = row
      self.controlChannel.visible = true
    },
    async handleControlChannelModify (row) {
      let self = this
      self.controlChannel.method = 'patch'
      self.controlChannel.id = row.id
      self.controlChannel.form.kind = row.kind
      self.controlChannel.form.power = row.power
      self.controlChannel.form.down_freq_point = row.down_freq_point
      self.controlChannel.visible = true
    },
    async handleControlChannelDelete (row) {
      let self = this
      try {
        await self.$confirm(self.$t('message.satelliteResource.dialog.controlChannel.form.deleteConfirm'), self.$t('message.common.label.prompt'), {
          confirmButtonText: self.$t('message.common.button.confirm'),
          cancelButtonText: self.$t('message.common.button.cancel'),
          type: 'warning'
        })
      } catch (e) {
        return
      }
      await self.$store.dispatch(`axios`, {
        method: 'delete',
        url: `/api/abs/resources/control_channels/${row.id}/`
      })
      self.$message({
        message: self.$t('message.common.info.deleteSuccess'),
        type: 'success'
      })
      self.getControlChannelsTableData()
    },
    async handleControlChannelDialogOpen () {
      let self = this
      try {
        self.controlChannel.loading = true
        await self.$store.dispatch(`getControlChannelType`)
        self.controlChannel.kindOption = [...self.$store.getters.getControlChannelType]
      } finally {
        self.controlChannel.loading = false
      }
    },
    handleControlChannelDialogClosed () {
      let self = this
      self.controlChannel.method = ''
    },
    async submitForm (formName) {
      let self = this
      try {
        await self.$refs[formName].validate()
      } catch (e) {
        return
      }
      // 卫星
      if (formName === 'satelliteForm') {
        self.satellite.buttonLoading = true
        try {
          if (self.satellite.method === 'post') {
            await self.$store.dispatch(`axios`, {
              method: 'post',
              url: '/api/abs/resources/satellites/',
              data: self.satellite.form
            })
          } else if (self.satellite.method === 'patch') {
            await self.$store.dispatch(`axios`, {
              method: 'patch',
              url: `/api/abs/resources/satellites/${self.satellite.id}/`,
              data: {
                name: self.satellite.form.name,
                distance: self.satellite.form.distance,
                longitude: self.satellite.form.longitude,
                latitude: self.satellite.form.latitude,
                gt: self.satellite.form.gt
              }
            })
          }
        } finally {
          self.satellite.buttonLoading = false
        }
        self.satellite.method === 'post'
          ? self.$message.success(self.$t('message.common.info.addSuccess'))
          : self.$message.success(self.$t('message.common.info.modifySuccess'))
        self.satellite.visible = false
        await self.getSatelliteTree()
        self.handleSatelliteTreeUpdate()
      }
      // 波束
      if (formName === 'beamForm') {
        self.beam.buttonLoading = true
        try {
          if (self.beam.method === 'post') {
            await self.$store.dispatch(`axios`, {
              method: self.beam.method,
              url: '/api/abs/resources/beams/',
              data: {
                satellite: self.beam.satellite,
                ...self.beam.form
              }
            })
          } else if (self.beam.method === 'patch') {
            await self.$store.dispatch(`axios`, {
              method: 'patch',
              url: `/api/abs/resources/beams/${self.beam.id}/`,
              data: {
                name: self.beam.form.name
              }
            })
          }
        } finally {
          self.beam.buttonLoading = false
        }
        self.beam.visible = false
        self.beam.method === 'post'
          ? self.$message.success(self.$t('message.common.info.addSuccess'))
          : self.$message.success(self.$t('message.common.info.modifySuccess'))
        await self.getSatelliteTree()
        self.handleSatelliteTreeUpdate()
      }
      // 转发器
      if (formName === 'transponderForm') {
        self.transponder.buttonLoading = true
        try {
          if (self.transponder.method === 'post') {
            await self.$store.dispatch(`axios`, {
              method: 'post',
              url: '/api/abs/resources/transponders/',
              data: {
                down_beam: self.transponder.down_beam,
                ...self.transponder.form,
                frequency_difference: self.transponder.form.frequency_difference * 1000
              }
            })
          } else if (self.transponder.method === 'patch') {
            await self.$store.dispatch(`axios`, {
              method: 'patch',
              url: `/api/abs/resources/transponders/${self.transponder.id}/`,
              data: {
                ...self.transponder.form,
                frequency_difference: undefined
              }
            })
          }
        } finally {
          self.transponder.buttonLoading = false
        }
        self.transponder.visible = false
        self.transponder.method === 'post'
          ? self.$message.success(self.$t('message.common.info.addSuccess'))
          : self.$message.success(self.$t('message.common.info.modifySuccess'))
        await self.getSatelliteTree()
        self.handleSatelliteTreeUpdate()
      }
      // 可用频率
      if (formName === 'freqSegmentForm') {
        try {
          self.freqSegment.buttonLoading = true
          if (self.freqSegment.method === 'post') {
            await self.$store.dispatch(`axios`, {
              method: 'post',
              url: '/api/abs/resources/freq_segments/',
              data: {
                transponder: self.freqSegment.transponder,
                up_beam: self.freqSegment.form.up_beam,
                down_freq_begin: self.freqSegment.form.down_freq_begin * 1000,
                down_freq_end: self.freqSegment.form.down_freq_end * 1000
              }
            })
          } else if (self.freqSegment.method === 'patch') {
            await self.$store.dispatch(`axios`, {
              method: 'patch',
              url: `/api/abs/resources/freq_segments/${self.freqSegment.id}/`,
              data: {
                up_beam: self.freqSegment.form.up_beam,
                down_freq_begin: self.freqSegment.form.down_freq_begin * 1000,
                down_freq_end: self.freqSegment.form.down_freq_end * 1000
              }
            })
          }
        } finally {
          self.freqSegment.buttonLoading = false
        }
        self.freqSegment.visible = false
        // 添加、修改成功
        self.freqSegment.method === 'post'
          ? self.$message.success(self.$t('message.common.info.addSuccess'))
          : self.$message.success(self.$t('message.common.info.modifySuccess'))
        self.getFreqSegmentTableData()
      }
      // 可用时间段
      if (formName === 'timePeriodForm') {
        try {
          self.timePeriod.buttonLoading = true
          if (self.timePeriod.model === 'post') {
            await self.$store.dispatch(`axios`, {
              method: 'post',
              url: `/api/abs/resources/freq_segment_service_time/`,
              data: {
                freq_segment: self.timePeriod.freq_segment,
                start_time: common.convertDateTimeToTime(self.timePeriod.form.start_time),
                end_time: common.convertDateTimeToTime(self.timePeriod.form.end_time)
              }
            })
          } else if (self.timePeriod.model === 'patch') {
            await self.$store.dispatch(`axios`, {
              method: 'patch',
              url: `/api/abs/resources/freq_segment_service_time/${self.timePeriod.id}/`,
              data: {
                start_time: common.convertDateTimeToTime(self.timePeriod.form.start_time),
                end_time: common.convertDateTimeToTime(self.timePeriod.form.end_time)
              }
            })
          }
          self.timePeriod.method === 'post'
            ? self.$message.success(self.$t('message.common.info.addSuccess'))
            : self.$message.success(self.$t('message.common.info.modifySuccess'))
          self.timePeriod.visible = false
          self.getFreqSegmentTableData()
        } finally {
          self.timePeriod.buttonLoading = false
        }
      }
      // 控制信道
      if (formName === 'controlChannelForm') {
        let halfFreqDiff = self.controlChannel.kindOption.find(item => {
          return item.kind === self.controlChannel.form.kind
        }).band_width * 1000 / 2
        let downFreqBegin = self.controlChannel.form.down_freq_point * 1000 - halfFreqDiff
        let downFreqEnd = self.controlChannel.form.down_freq_point * 1000 + halfFreqDiff
        try {
          self.controlChannel.buttonLoading = true
          if (self.controlChannel.method === 'post') {
            await self.$store.dispatch(`axios`, {
              method: 'post',
              url: `/api/abs/resources/control_channels/`,
              data: {
                freq_segment: self.controlChannel.freqSegment,
                kind: self.controlChannel.form.kind,
                down_freq_begin: downFreqBegin,
                down_freq_end: downFreqEnd,
                power: self.controlChannel.form.power
              }
            })
          } else if (self.controlChannel.method === 'patch') {
            await self.$store.dispatch(`axios`, {
              method: 'patch',
              url: `/api/abs/resources/control_channels/${self.controlChannel.id}/`,
              data: {
                down_freq_begin: downFreqBegin,
                down_freq_end: downFreqEnd,
                power: self.controlChannel.form.power
              }
            })
          }
          self.getControlChannelsTableData()
        } finally {
          self.controlChannel.buttonLoading = false
        }
        self.controlChannel.visible = false
        // 添加、修改成功
        self.controlChannel.method === 'post'
          ? self.$message.success(self.$t('message.common.info.addSuccess'))
          : self.$message.success(self.$t('message.common.info.modifySuccess'))
      }
    },
    // 数据同步
    async handleDataSynchronize () {
      console.log(this);
      let self = this
      console.log(123);
      await self.$store.dispatch(`axios`, {
        method: 'post',
        url: `/api/abs/ncp/refresh_all_sam/`
      })
      self.$message.success('同步成功')
    }
  }
}
</script>

<style scoped>

</style>
